home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8551 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  66 lines

  1. Path: news.azstarnet.com!usenet
  2. From: Howard Salmon <captarm@azstarnet.com>
  3. Newsgroups: comp.lang.c
  4. Subject: how can an int data type accept char data?
  5. Date: 5 Mar 1996 00:46:10 GMT
  6. Organization: Arizona Daily Star - AZSTARNET
  7. Message-ID: <4hg2si$irt@news.azstarnet.com>
  8. NNTP-Posting-Host: usr9ip52.azstarnet.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.12(Macintosh; I; 68K)
  13. X-URL: news:comp.lang.c
  14.  
  15. I thought that the int data type could only accept integer data; 
  16. however, the example listed below (taken from Dave Mark's book "Learn C 
  17. on the Macintosh") shows an int variable ("done") accepting character 
  18. data (i.e. "FALSE").  Dave Mark doesnt explain this.  Can anyone help me 
  19. out? (This is a program is supposed to find the prime number that 
  20. follows a previous prime number):
  21.  
  22. #include <stdio.h>
  23.  
  24. main()
  25. {
  26.     int        startingPoint, candidate, i;
  27.     int        done, foundFactor;
  28.     
  29.     done = FALSE; 
  30.  
  31.                 {how can a variable declared as an integer
  32.                     hold character variables?  Why wouldn't
  33.                     C insist on a char data type? } 
  34.                     
  35.     startingPoint = 19;
  36.     candidate = startingPoint;
  37.     
  38.     while ( ! done )
  39.     {
  40.         candidate++;
  41.         
  42.         foundFactor = FALSE;  
  43.  
  44.                             {...same with the "foundFactor" 
  45.                                 variable.  It's declared as an 
  46.                                 integer, yet it's accepting alphanumeric 
  47.                                 characters...}
  48.                                 
  49.         for ( i = 2; i < candidate; i++ )
  50.         {
  51.             if ( (candidate / i) * i == candidate )
  52.                 foundFactor = TRUE;
  53.         }
  54.         
  55.         done = (foundFactor == FALSE);
  56.     }
  57.     
  58.     printf( "The next prime after %d is %d.  Happy?",
  59.                     startingPoint, candidate );
  60. }
  61.  
  62. Thanks, 
  63. Howard Salmon (captarm@azstarnet.com)
  64.  
  65.  
  66.